1. /* slfllsub.cpp by K.Tsuru */
  2. // function ID = 208 DRADIX, BRADIX
  3. /*************************************************************
  4. SLong and SInteger classes
  5. m - n ( m and n have the same sign, and |m|>|n|>0).
  6. *************************************************************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. static const char* const func = "\'-\' or LLSub";
  11. SLong LLSub(const SLong& m, const SLong& n) {
  12. if( m.Sign() != n.Sign() ) m.SetError(m.SYNTAX_ERR, func, 208);
  13. SLong result(m); // result = m
  14. if( (n.aHead > 0) && ( m.Radix() != n.Radix() ) ){
  15. m.SetError(m.RADIX_ERR, func, 208);
  16. }
  17. int k = 0;
  18. long rdx = (long)m.Radix();
  19. long w;
  20. const fType* mv = m.ReadFigures();
  21. const fType* nv = n.ReadFigures();
  22. fType* rv = result.figure.Elements(); //*
  23. // Here, result = m.
  24. uint i;
  25. for(i = n.aTail; i <= n.aHead ; i++){
  26. w = (long)mv[i] - (long)nv[i] + k; // -radix <= w < radix
  27. if( w < 0 ) { k = -1; w += rdx;
  28. } else k = 0;
  29. rv[i] = (fType)w;
  30. }
  31. for( ; k && (i<= m.aHead); i++){
  32. //Here nv[i] = 0.
  33. w = (long)mv[i] + k;
  34. if( w < 0 ) { k = -1; w += rdx;
  35. } else k = 0;
  36. rv[i] = (fType)w;
  37. }
  38. if(k) m.SetError(m.SYNTAX_ERR, func, 208);
  39. //It gets the figure position.
  40. uint rh = m.aHead, rt = min(m.Tail(), n.Tail()); // aTail --> Tail() since ver 2.191
  41. #ifndef NDEBUG
  42. result.figure(rh);
  43. #endif
  44. while(!rv[rh]) rh--;
  45. while(!rv[rt]) rt++;
  46. result.aHead = rh;
  47. result.aTail = rt;
  48. result.SetSign(m.Sign());
  49. result.DoCutDown(); //It reduces the size if possible.
  50. return result;
  51. }

slfllsub.cpp : last modifiled at 2017/03/13 14:32:00(1,588 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).